<?php
namespace app\index\controller;
use think\Db;
use think\Controller;
use Vendor\Alidayu;
class Aliapp extends Controller
{
    public function appPay() {
        //alipay.AopSdk
        vendor("wapAliPay.wappay.service.AlipayTradeService");
        vendor("wapAliPay.wappay.buildermodel.AlipayTradeWapPayContentBuilder");
        $config = array (
            //应用ID,您的APPID。
            'app_id' => "2018072460765191",
            //商户私钥，您的原始格式RSA私钥
            'merchant_private_key' => "MIIEogIBAAKCAQEA8p088socxeyHdbmIdkB/DibLNWN8S02UIB+GL738x03wgwCwTMv0q0zatawxOx5m0HY+JuFcDnv6/AqC05CbNxKwqF1Dv2+kMvhk8TBJZS5Zp4rhWtWrL8720umnAjgJnAgEq4+284jQ0iMEpqH9OqcOSq5FBVvejUHhrXySELdui21uWVBl0862cHdS3kj60iJZuIuW+66a9LmZMFC/wuxi6DkMfJtVxQNDGGXQFo1kS6J80B/rW8XHJHWgfQsaeFFLQLIgEDyz1s5VGP+Xe9a+mfulNB1tjYEF8TCYDaOwQPgcpofGMagk+kRr+XxyoHGOOIir7WbO6ZFZtuzWiwIDAQABAoIBAEU58IYmfYdMMmq5AeMcDCTxlNIrDPA/tqBj3loJD/OenZ4DuEpxd+LZDx7/fxyrVBLvalSVwTqwzbDVHvdXL7LLNnUUB5y8MlII5mSbrpWcYCCaVCsjBLGjkHImEW1kp/lJoGuDmmRrCYqsS0twtVzjBgTxLOiWii4sOkTSYqs53aPK35vGz8/Kntvu3qEN0U8TkGRPKWqRj1mTJLjxHA03SWYlW87R5kjEwm9tLXM/JlIQJcGIZ1QE7aeZoRzIY9UdZhXzBSw/85Fx4eI6Yd2aIAeV0Zju2BzVEwyDZmjYXamiPYm5JazNdT5F8JYh1qbrZvmnIY7iBDTeSIFcioECgYEA/pAQD83sOuutkt+N59n5x5B+eS/3jGtWZlH3hdRRvXx/Gkhh+wJmhnfgH0STtyp5wn77Vjkjv3H9RuGQ7lzyRBW1hIK/enf+nccylIIBAjl54pN9XMOQvcrSShdC2wyJmI0EGe7y2GyTmcaLnP5qOSBS99UEF9rrm1Z6Z4DnxTECgYEA8/vnwSE8CN2VFT0pO3ycDM2X1lmZ0ndxbGSEcJ0GcUuVVOz1Us2G0v0JlAbcmWG/D+dlfyrcSjB5WdAgpcWBJUXXzbSRoBLxXu0zHcnqwkWJ9XcNoHR8dqahJ7SaoNrJgdqdVn/az1oJnl8aPbQD3e60jCJhUv2Rqk7hUWM8mHsCgYBfUdpx0I3QUkegY41jb7+T9oslHcz4C4lCrxacSjCBX4jIcqodr3xshZ6qlqcpQwJszdeXJbY5DZnlXLlESBF/ZRGfGMZSOXRh6CEMctGl35fAO7IJdkFQkA3GKIekNkGfmc4bV9ofKCjsv+evVaS41125502tERCADhWvhBlFQQKBgG+/pCF4GGgzHTJyJe2CIHNYwz/BIEweuwubanGt6iKALPCN67s2OZdvoDB1iBqUg49EO9+oAOfWFe7F/f4PXRx2ReaI2t5Hbtg8qlntfqHmec687bfdQpiRr2RhOyWLsBnSyJeyzcSFB7zK8Fjsl4zR5U39/Temvk4T/O1rF3j7AoGAS24U0FGwlLo+T7ruYpK7UgD9ssrm8TXLPjCaXdEaTmSbFjDn5FHiF7/svgPOLu/sEhwTWi0qLn0V+v+H8nVcZEdpdCkYxmW56pRoOMqJMd8iuPpjvw077EM/Q+GLOauZg6mQPzWptlZOQT1aAB6EZmBlLC2ebt9BIKTqkOdi/zI=",
            //异步通知地址
            'notify_url' => "http://pay.7kid.com/index/Aliapp/index",
            //同步跳转
            'return_url' => "http://pay.7kid.com/index/Aliapp/index",
            //编码格式
            'charset' => "UTF-8",
            //签名方式
            'sign_type'=>"RSA2",
            //支付宝网关
            'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
            //支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
            'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0iabm/CCJr7lRCOdVDhL GClVkBMOD4sncZfdtYpxVwFMEVyBLix1Zop7WjSheSje7z+zYCxkDGasE//C7KVf vR79jSULEYG0Cg/5dZDtaavi2hQEuqVqWXuSSBQwxXSw0gDRrcyQPBCTkNDNihD9 1gUBbAZ13F7sQCskVZUTQXiCDRb4581EPwf1j0458mo1eplMwQHlEdB5sUFH4tsF Mi00VEf9ofhtMVq5X2COt3ScdoCGsgwgjBE4xQV30qvDI5JV6yL8tinWa7Ez0BiT OWh7ApkRU3Pbvdz2HcFyuGWdMb5kz6zOwfQ+IKvLid1mf20/hqxm+wSnH01tyuxS TwIDAQAB",
        );

        $out_trade_no = $_REQUEST['WIDout_trade_no'];
        //订单名称，必填
        $subject = $_REQUEST['WIDsubject'];
        //付款金额，必填
        $total_amount = $_REQUEST['WIDtotal_amount'];
        //商品描述，可空
        $body = $_REQUEST['WIDbody'];
        //超时时间
        $timeout_express="1m";
        $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
        $payRequestBuilder->setBody($body);
        $payRequestBuilder->setSubject($subject);
        $payRequestBuilder->setOutTradeNo($out_trade_no);
        $payRequestBuilder->setTotalAmount($total_amount);
        $payRequestBuilder->setTimeExpress($timeout_express);

        $payResponse = new \AlipayTradeService($config);
        $result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url']);
    }


    /**
     * 商城主页
     */
    public function index() {

        return $this->fetch();
    }
}
